// axios的基础封装
import axios from "axios";
import {ElMessage} from "element-plus";

const httpInstance = axios.create({
    baseURL: '/api',
    timeout: 10000,
});

// axios响应式拦截器
httpInstance.interceptors.response.use(
    result => {
        if (result.data.code === 100200) {
            return result.data;
        }
        // 操作失败
        ElMessage.error(result.data.message ? result.data.message : '服务异常');
        return Promise.reject(result.data);
    }, error => {
        console.log(error);
        return Promise.reject(error); //异步的状态转化成失败的状态
    }
)

export default httpInstance